package com.qzdsoft.erpcloud.service.basic.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.qzdsoft.erpcloud.domain.basic.DataDictionaryValue;
import com.qzdsoft.erpcloud.mapper.basic.DataDictionaryValueMapper;
import com.qzdsoft.erpcloud.service.basic.DataDictionaryValueService;
import com.qzdsoft.erpcloud.vo.query.basic.DataDictionaryValueInfo;
import com.qzdsoft.utils.constant.SystemConstant;
import com.qzdsoft.vo.LayTableResponse;
import com.qzdsoft.vo.Response;
import com.qzdsoft.vo.ResultEnum;

/**
 * Created by Admin
 */
@Service
public class BasicDataDictionaryValueServiceImpl implements DataDictionaryValueService {

    @Autowired
    private DataDictionaryValueMapper basicDataDictionaryValueMapper;

    @Override
    public DataDictionaryValue selectById(Integer id) {
        return basicDataDictionaryValueMapper.selectByPrimaryKey(id);
    }

    @Override
    public Response<String> saveOrUpd(DataDictionaryValue basicDataDictionaryValue) {
        if(null == basicDataDictionaryValue.getCompany_id()){
            basicDataDictionaryValue.setCompany_id(SystemConstant.companyIdGg);
        }
        if(null != basicDataDictionaryValue.getId()){
            basicDataDictionaryValueMapper.updateByPrimaryKey(basicDataDictionaryValue);
        } else {
            basicDataDictionaryValue.setCtime(new Date());
            basicDataDictionaryValueMapper.insert(basicDataDictionaryValue);
        }
        return new Response<String>(ResultEnum.SUCCESS);
    }

    @Override
    public Response<String> del(Integer id) {
        basicDataDictionaryValueMapper.deleteByPrimaryKey(id);
        return new Response<String>(ResultEnum.SUCCESS);
    }

    @Override
    public LayTableResponse<DataDictionaryValueInfo> selectData(Integer typeId, Integer companyId, Integer isPreinstall, String decode, String value,String typeName, Integer start, Integer pageSize) {
        PageHelper.startPage(start, pageSize);
        List<DataDictionaryValueInfo> list = basicDataDictionaryValueMapper.selectData(typeId, companyId, isPreinstall, decode, value, typeName, start, pageSize);
        return new LayTableResponse<DataDictionaryValueInfo>(list);
    }
    //根据字典分组ID 查找List
	@Override
	public List<DataDictionaryValue> getByEnumId(Integer id) {
		return basicDataDictionaryValueMapper.getByEnumId(id);
	}
}
